﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Samples.ServiceHosting.StorageClient;

namespace Ciripescu_WebRole.Entities
{
    public class CiripCache : TableStorageEntity
    {
        
        public string From {get; set;}
        public string Content { get; set; }
        public string InReplyToUser { get; set; }
        public string InReplyToId { get; set; }
        public string Version { get; set; }
        // don't use TimeStamp because we may not be able to backup it
        public DateTime TimePosted { get; set; }


        public CiripCache(Cirip c) : base("",c.RowKey)
        {
            this.From = c.getUser();
            this.Content = c.Content;
            this.InReplyToId = c.InReplyToId;
            this.InReplyToUser = c.InReplyToUser;
            this.RowKey = c.RowKey;
            this.TimePosted = c.TimePosted;
            this.Version = c.Version;
        }
        public CiripCache(string user, string content)
            : base("",string.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks))
        {
            this.From = user;
            this.Content = content;
            this.Version = Properties.Settings.Default.Version;
            this.TimePosted = DateTime.Now;

            this.InReplyToUser = string.Empty;
            this.InReplyToId = string.Empty;
        }

        public CiripCache(string user, string content, string inReplyToUser, string inReplyToId)
            : base("", string.Format("{0:D19}", DateTime.MaxValue.Ticks - DateTime.UtcNow.Ticks))
        {  
            this.From = user;
            this.Content = content;
            this.Version = Properties.Settings.Default.Version;
            this.TimePosted = DateTime.Now;

            this.InReplyToUser = inReplyToUser;
            this.InReplyToId = inReplyToId;
        }
        public CiripCache() { }
        
        
        public string getId()
        {
            return RowKey;
        }
    }
}
